<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@page import="com.solution.common.config.PublicConfig"%>
<%
	String basePath = PublicConfig.ROOT_PATH;
	String imgRootURL = PublicConfig.IMG_ROOT_URL;
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>取消订单</title>
<link rel="stylesheet" type="text/css" href="<%=basePath%>/statics_wx/css/style.css">
<script src="<%=basePath%>/statics_wx/js/jquery.min.js"></script>
<script src="<%=basePath%>/statics_wx/js/js.js"></script>
<script type="text/javascript" src="<%=basePath%>/statics/plugins/layer/layer.js"></script>
<script>
$(function(){
	$('#lybtn').click(function(){
		$('#ly_box').toggle();
	});
	$('.ps_box dl dt label').click(function(){
		if($(this).hasClass('checked')){
			$(this).addClass('checked');
			x1 = $(this).find('strong').html();
			$('#lybtn').find('.txt1 p span').html(x1);
		}else{
			$(this).parent().find('input').attr('checked','checked');
			$(this).addClass('checked');
			$(this).parent().siblings().find('label').removeClass('checked');
			x1 = $(this).find('strong').html();
			$('#lybtn').find('.txt1 p span').html(x1);
		}
	});
	
	$("#btn_confirm_cancel_reason").click(function(){
		$('#ly_box').toggle();
	});
	
	// 确认取消
	$("#btn_confirm_cancel").click(function(){
		var cancel_reason = $("label.checked").find("strong").text();
		if (!cancel_reason || $.trim(cancel_reason) == '') {
			layer.msg('请选择取消理由类型',{time:1000});
			return false;
		}
		
		var order_code = $("#orderCode").val();
		var cancel_intro = $("#cancel_intro").val();
		
		var url = rootPath + "/wx/order/cancelOrder";
		var params = {
			orderCode : order_code,
			cancelReason: cancel_reason+(cancel_intro != null ? cancel_intro:"")
		};
		$.ajax({
			type : "post",
			url : url,
			data : params,
			datatype : "json",
			success : function(json) {
				if(json && json.resultCode == 1){
					layer.msg('订单取消成功',{time:1000});
					// 跳转订单列表页面
					setTimeout(function(){
						window.location.href = rootPath+"/wx/order/list";
					},1000);
				}else{
					layer.msg('订单取消失败',{time:1000});
				}
			},
			error : function() {
				layer.msg('订单取消失败',{time:1000});
			}
		});
	});
	//系统域名 
	var rootPath = '<%=basePath%>';
	// 系统上传文件展示域名
	var imgRootURL = '<%=imgRootURL%>';
});
</script>
</head>
<body style="background:#f5f5f5">
<c:set var="rootPath" value="<%=basePath %>"></c:set>
<c:set var="imgRootURL" value="<%=imgRootURL %>"></c:set>
<input type="hidden"  id="orderCode"  value="${orderCode }"/>
<div class="reg_tips2" style="display:none">
	<p>
    	<i></i>
        <span>提交成功</span>
    </p>
</div>
<div class="overlay" id="ly_box" style="display:none">
	<div class="ps_box">
    	<div class="hd">
        	<h3>理由类型</h3>
        </div>
        <div class="bd">
        	<dl>
        		<c:forEach items="${cancelReasonList }" var="reason">
        			<dt>
	                	<label reason_code="${reason.keyValue }"><strong>${reason.keyIntro }</strong><b></b></label>
	                </dt>
        		</c:forEach>
            </dl>
        </div>
        <div class="bottom">
        	<p>
            	<input type="button" id="btn_confirm_cancel_reason" class="inputbtn1" value="确 定" />
            </p>
        </div>
    </div>
</div>
<div class="cancel_part">
	<dl>
    	<dt><a href="#" id="lybtn">
        	<strong><em></em>理由类型</strong>
            <div class="txt1">
            	<p>
                	<span>请选择</span><i></i>
                </p>
            </div>
            </a>
        </dt>
        <dt>
        	<div class="textarea2">
            	<div class="textarea2_con">
                	<textarea id="cancel_intro" placeholder="请输入备注理由"></textarea>
                    <b><em id="txtLen">0</em>/50</b>
                </div>
            </div>
        </dt>
    </dl>
</div>
<div class="login_other">
    	<p>
        	<input type="button" id="btn_confirm_cancel"  class="inputbtn1" value="提 交" />
        </p>
    </div>
<script type="text/javascript">

	$(function() {
		$("#content").bind({"keyup": function (e) {
	  		$("#cl").empty();  
	    	$("#cl").append(smartLen($(this).val()));  
	    	checkWords($(this).val());
	  	}});  
    });
	var urlReg ={"urlRegText":"((news|telnet|nttp|file|http|ftp|https)://){1}(([-A-Za-z0-9]+(\\.[-A-Za-z0-9]+)*(\\.[-A-Za-z]{2,5}))|([0-9]{1,3}(\\.[0-9]{1,3}){3}))(:[0-9]*)?(/[-A-Za-z0-9_\\$\\.\\+\\!\\*\\(\\),;:@&=\\?/~\\#\\%]*)*"  
};  
// 字符串长度  
function smartLen(str) {  
    str = str.replace(/(^[\s\n]+)|([\s\n]+$)/,"").replace(/[\s\n]+/g," ");  
    str = str.replace(new RegExp(urlReg.urlRegText, "gi"), new Array(12).join("aa"));  
    return Math.ceil(($.trim(str.replace(/[^\u0000-\u00ff]/g, "aa")).length) / 2);  
}
function checkWords(content){  
    var len = 50-smartLen(content);  
      if (len < 0) {  
        $('#txtLen').html(0);  
        layer.msg('备注理由超出限制',{time:1000});
    } else {  
        $('#txtLen').html( len );     
    }  
}  
</script>

</body>
</html>